namespace LDNS.SDK.Commands.Models
{
    /// <summary>
    /// 服务状态命令
    /// 用于查询DNS服务的当前运行状态
    /// 作者：huobing
    /// </summary>
    public sealed class StatusCommand : BaseCommand<StatusResult>
    {
        public const string NAME = "STATUS";
        public override string Name => NAME;
        public override string Format => "STATUS";
        public override string Description => "显示DNS服务状态";
        public override CommandPermission Permission => CommandPermission.User;
        public override bool Validate(string[] args, out string error) 
        { 
            error = string.Empty; 
            return args.Length == 0 || (error = "此命令不接受参数") == string.Empty; 
        }
    }
    
    /// <summary>
    /// 服务状态命令执行结果
    /// 作者：huobing
    /// </summary>
    public class StatusResult : BaseCommandResult
    {
        /// <summary>
        /// 服务是否正在运行
        /// </summary>
        public bool IsRunning { get; set; }

        /// <summary>
        /// 服务监听地址
        /// </summary>
        public string? ListenAddress { get; set; }

        /// <summary>
        /// 服务监听端口
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// 服务版本信息
        /// </summary>
        public string? Version { get; set; }
        
        /// <summary>
        /// 控制台输出格式化
        /// </summary>
        /// <returns>格式化后的状态信息</returns>
        public override string ToConsoleString()
        {  
            var sb = new System.Text.StringBuilder();
            sb.AppendLine("服务状态信息：");
            sb.AppendLine($"  运行状态: {(IsRunning ? "运行中" : "未运行")}");
            sb.AppendLine($"  监听地址: {(ListenAddress ?? "0.0.0.0")}:{Port}");
            sb.AppendLine($"  版本信息: {Version ?? "未指定"}");
            
            return sb.ToString().TrimEnd();
        }
    }
}